package com.example.teesystem.controller;

import com.example.teesystem.common.Permission.PermissionCheck;
import com.example.teesystem.common.utils.PermissionUtil;
import com.example.teesystem.common.utils.Response;
import com.example.teesystem.common.utils.ResultCode;
import com.example.teesystem.entity.vo.examEvaluation.WordVo;
import com.example.teesystem.service.ExamEvaluationService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Map;

/**
 * @author : NieYaShi
 * @version : v1.0
 * @createTime : 2022/4/19 14:49
 */
@RestController
@RequestMapping(value = "/tee/examEvaluation", produces = "application/json; charset=utf-8")
@RequiredArgsConstructor
public class ExamEvaluationController {
    private final ExamEvaluationService examEvaluationService;
    private final HttpServletResponse response;

//    /**
//     * 学生端获取不同类型题目的答题正确率
//     * @return
//     */
//    @PostMapping(value = "/getStudentIssueCorrect")
//    public Response getStudentIssueCorrect(){
//        return examEvaluationService.getStudentIssueCorrect();
//    }
//
//    /**
//     *  学生端获取不同类型题目的平均难度
//     * @return
//     */
//    @PostMapping(value = "/getStudentIssueAvgDifficulty")
//    public Response getStudentIssueAvgDifficulty(){
//        return examEvaluationService.getStudentIssueAvgDifficulty();
//    }

    /**
     * 试卷画像——获取题目类型分布
     * @param map
     * @return
     */
    @PostMapping(value = "/getExamIssueTypeDistribution")
    public Response getExamIssueTypeDistribution(@RequestBody Map<String, String> map){
        int courseId, paperId;
        try {
            courseId = Integer.parseInt(map.get("courseId"));
            paperId = Integer.parseInt(map.get("paperId"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS);
        }
        return examEvaluationService.getExamIssueTypeDistribution(courseId, paperId);
    }

    /**
     * 试卷画像——获取不同题型平均难度
     * @param map
     * @return
     */
    @PostMapping(value = "/getExamIssueTypeAvgDifficulty")
    public Response getExamIssueTypeAvgDifficulty(@RequestBody Map<String, String> map){
        int courseId, paperId;
        try {
            courseId = Integer.parseInt(map.get("courseId"));
            paperId = Integer.parseInt(map.get("paperId"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS);
        }
        return examEvaluationService.getExamIssueTypeAvgDifficulty(courseId, paperId);
    }

    /**
     * 试卷画像——获取不同题型总分
     * @param map
     * @return
     */
    @PostMapping(value = "/getExamIssueScoreDistribution")
    public Response getExamIssueScoreDistribution(@RequestBody Map<String, String> map){
        int courseId, paperId;
        try {
            courseId = Integer.parseInt(map.get("courseId"));
            paperId = Integer.parseInt(map.get("paperId"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS);
        }
        return examEvaluationService.getExamIssueScoreDistribution(courseId, paperId);
    }

    /**
     * 试卷画像——获取学生分值分布
     * @param map
     * @return
     */
    @PostMapping(value = "/getExamScoreDistribution")
    public Response getExamScoreDistribution(@RequestBody Map<String, String> map){
        int courseId, paperId;
        try {
            courseId = Integer.parseInt(map.get("courseId"));
            paperId = Integer.parseInt(map.get("paperId"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS);
        }
        return examEvaluationService.getExamScoreDistribution(courseId, paperId);
    }

    /**
     * 试卷画像——获取试卷知识点分布
     * @param map
     * @return
     */
    @PostMapping(value = "/getExamKnowledgeDistribution")
    public Response getExamKnowledgeDistribution(@RequestBody Map<String, String> map){
        int courseId, paperId;
        try {
            courseId = Integer.parseInt(map.get("courseId"));
            paperId = Integer.parseInt(map.get("paperId"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS);
        }
        return examEvaluationService.getExamKnowledgeDistribution(courseId, paperId);
    }

    /**
     * 题库画像——获取题库题型分布
     * @param map
     * @return
     */
    @PostMapping(value = "/getIssueTypeDistribution")
    public Response getIssueTypeDistribution(@RequestBody Map<String, String> map){
        int courseId, trainingExam;
        try {
            courseId = Integer.parseInt(map.get("courseId"));
            trainingExam = Integer.parseInt(map.get("trainingExam"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS);
        }
        return examEvaluationService.getIssueTypeDistribution(courseId, trainingExam);
    }

    /**
     * 题库画像——获取题库不同题型平均难度
     * @param map
     * @return
     */
    @PostMapping(value = "/getIssueTypeAvgDifficulty")
    public Response getIssueTypeAvgDifficulty(@RequestBody Map<String, String> map){
        int courseId, trainingExam;
        try {
            courseId = Integer.parseInt(map.get("courseId"));
            trainingExam = Integer.parseInt(map.get("trainingExam"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS);
        }
        return examEvaluationService.getIssueTypeAvgDifficulty(courseId, trainingExam);
    }

    /**
     * 题库画像——获取题库难度分布
     * @param map
     * @return
     */
    @PostMapping(value = "/getIssueDifficultyDistribution")
    public Response getIssueDifficultyDistribution(@RequestBody Map<String, String> map){
        int courseId, trainingExam;
        try {
            courseId = Integer.parseInt(map.get("courseId"));
            trainingExam = Integer.parseInt(map.get("trainingExam"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS);
        }
        return examEvaluationService.getIssueDifficultyDistribution(courseId, trainingExam);
    }

    /**
     * 预警——获取章节正确率
     * @param map
     * @return
     */
    @PostMapping(value = "/getChapterCorrectRate")
    public Response getChapterCorrectRate(@RequestBody Map<String, String> map){
        int courseId, studentId;
        try {
            courseId = Integer.parseInt(map.get("courseId"));
            studentId = Integer.parseInt(map.get("studentId"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS);
        }
        return examEvaluationService.getChapterCorrectRate(courseId, studentId);
    }

    /**
     * 预警——获取学生考试正确率
     * @param map
     * @return
     */
    @PostMapping(value = "/getStudentExamCondition")
    public Response getStudentExamCondition(@RequestBody Map<String, String> map){
        int courseId, studentId;
        try {
            courseId = Integer.parseInt(map.get("courseId"));
            studentId = Integer.parseInt(map.get("studentId"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS);
        }
        return examEvaluationService.getStudentExamCondition(courseId, studentId);
    }

    /**
     * 预警——获取学生训练正确率
     * @param map
     * @return
     */
    @PostMapping(value = "/getStudentTrainingCorrectRate")
    public Response getStudentTrainingCorrectRate(@RequestBody Map<String, String> map){
        int courseId, studentId;
        try {
            courseId = Integer.parseInt(map.get("courseId"));
            studentId = Integer.parseInt(map.get("studentId"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS);
        }
        return examEvaluationService.getStudentTrainingCorrectRate(courseId, studentId);
    }

    @RequestMapping(value = "/getWordPaper")
    @PermissionCheck(PermissionUtil.PAPER_RELEASE)
    public Response getWordPaper(@Valid @RequestBody WordVo wordVo){
        return examEvaluationService.getWord(wordVo,response);
    }
}
